/**
 * 项目名：phms3
 * 日期：    2019-11-23 18:57:25
 * Copyright (c) 2015- HTSC-版权所有
 */

package com.joysuch.wwyt.mh.repository;

import com.joysuch.wwyt.mh.entity.MhMajorHazardChemProduct;
import com.joysuch.wwyt.mh.entity.MhMajorHazardChemProductRel;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;

import java.util.List;

/**
 * MhMajorHazardChemProductRelDao
 */
public interface MhMajorHazardChemProductRelDao extends JpaRepository<MhMajorHazardChemProductRel, Long>,
        QuerydslPredicateExecutor<MhMajorHazardChemProductRel> {

    public Page<MhMajorHazardChemProductRel> findAll(Specification<MhMajorHazardChemProductRel> spec,
                                                     Pageable pageable);

    public MhMajorHazardChemProductRel save(MhMajorHazardChemProductRel bean);

    public void delete(MhMajorHazardChemProductRel bean);

//    @Modifying
//    @Query(value = "UPDATE wwyt_bp_device_facility_collection SET delete_flag = '1' WHERE major_hazard_id =?1 ", nativeQuery = true)
//    public void deleteByMajorHazardId(Long id);

    public void deleteByMhMajorHazardChemProduct(MhMajorHazardChemProduct product);

    @Query(value = "select * from wwyt_mh_major_hazard_chem_product_rel where " + "CHEM_PRODUCT_ID=:pId and " + "MAJOR_HAZARD_ID =:mId and delete_flag = '0'", nativeQuery = true)
    List<MhMajorHazardChemProductRel> findIdByPidAndMid(Long pId, Long mId);

    List<MhMajorHazardChemProductRel> findByMhMajorHazardChemProduct(MhMajorHazardChemProduct one);
}
